package com.bdb.myswipemultitype.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.SupportActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.Toast;

import com.bdb.myswipemultitype.R;
import com.bdb.myswipemultitype.bean.ItemBean;
import com.bdb.myswipemultitype.bean.ItemNoBean;
import com.bdb.myswipemultitype.bean.ItemNoProvider;
import com.bdb.myswipemultitype.bean.ItemProvider;
import com.bdb.myswipemultitype.swipeListview.swipeMenuRecycle.SwipeAdapter;
import com.bdb.myswipemultitype.swipeListview.swipeMenuRecycle.SwipeMenuRecyclerView;

import me.drakeet.multitype.Items;

/**
 * Created by zinc on 2017/5/15.
 */

public class ListActivity extends SupportActivity {

    private Items items;
    private SwipeAdapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);

        final SwipeMenuRecyclerView swipeMenuRecyclerView = (SwipeMenuRecyclerView)findViewById(R.id.recycleview);
        items = new Items();
        adapter = new SwipeAdapter(items);

        adapter.register(ItemBean.class, new ItemProvider());
        adapter.register(ItemNoBean.class, new ItemNoProvider());

        adapter.setLayoutId(R.id.swipe);
        adapter.setMenuId(R.id.right_menu);
        adapter.setListener(new SwipeAdapter.SwipeListener() {
            @Override
            public void menuClick(View v, int position) {

                Toast.makeText(ListActivity.this, "menu:"+v.getId()+";position:"+position, Toast.LENGTH_SHORT).show();

            }

        });

        swipeMenuRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        swipeMenuRecyclerView.setAdapter(adapter);

        for(int i=0; i<4000; ++i){
            ItemBean itemBean = new ItemBean();
            ItemNoBean itemNoBean = new ItemNoBean();
            itemBean.setName(i+":这是个测试 哈哈哈哈哈哈哈哈哈哈");
            itemNoBean.setName(i+":哈哈");
            items.add(itemBean);
            items.add(itemNoBean);
        }
        adapter.notifyDataSetChanged();

    }
}
